<div class="main">
	<?php if(!isset($_SESSION['user_id'])) { ?>
	<form action="inscription.php" method="post" class="center-block half-size">
		<div class="input-group input-group-lg">
					<span class="input-group-addon inscription">
						<label for="pseudo">Pseudo</label>
					</span>
			<input type="text" name="pseudo" id="pseudo" value="<?php if(isset($pseudo)){echo($pseudo);} ?>" class="form-control" required autofocus />
		</div>
		<br />
		<div class="input-group input-group-lg">
					<span class="input-group-addon inscription">
						<label for="pwd">Password</label>
					</span>
			<input type="password" name="password" id="pwd" value="" class="form-control" />
		</div>
		<br />
		<div class="input-group input-group-lg">
					<span class="input-group-addon inscription">
						<label for="pwd2">Confirmation Pwd</label>
					</span>
			<input type="password" name="password2" id="pwd2" value="" class="form-control" />
		</div>
		<br />
		<div class="input-group input-group-lg">
					<span class="input-group-addon inscription">
						<label for="nom">Nom</label>
					</span>
			<input type="text" name="nom" id="nom" value="<?php if(isset($nom)){echo($nom);} ?>" class="form-control" required />
		</div>
		<br />
		<div class="input-group input-group-lg">
					<span class="input-group-addon inscription">
						<label for="prenom">Prénom</label>
					</span>
			<input type="text" name="prenom" id="prenom" value="<?php if(isset($prenom)){echo($prenom);} ?>" class="form-control" required />
		</div>
		<br />
		<div class="input-group input-group-lg">
					<span class="input-group-addon inscription">
						<label for="email">E-mail</label>
					</span>
			<input type="email" name="email" id="email" value="<?php if(isset($email)){echo($email);} ?>" class="form-control" required />
		</div>
		<br />
		<button type="submit" name="valider" class="btn btn-success btn-lg btn-block">Envoyer</button>
	</form>
	<?php if(isset($error)) { ?>
		<br />
		<div class="alert alert-danger center-block text-center half-size">
			<?= $error ?> déja utilisé !
		</div>
	<?php }
	if(isset($error_pwd)) { ?>
		<br />
		<div class="alert alert-danger center-block text-center half-size">
			<?= $error_pwd ?>
		</div>
	<?php }
	}else { ?>
		<div class="alert alert-danger center-block text-center half-size">
			Vous êtes déjà connecté !
		</div>
	<?php } ?>
</div>

<script>
function checkAll()
{
	close('info_submit');
	var input = document.getElementsByTagName('input');
	for (var i = 0; i <input.length ; i++)
	{
		var j = i;
		if (input[i].className == 'incorrect') 
		{   
			
			break;
		}
	}
	
	if (input[j].className == 'incorrect') 
	{   
		display('info_submit');
	}
	else
	{
		close('step1');
		display('step2');
	}
}

function check(inputForm, type)
{
	var input  = document.getElementById(inputForm);
	switch (type)
	{
		case"username":
			if(/[a-zA-Z0-9]/.test(input.value)&& input.value.length >= 6 && input.value.length <= 19 )
			{	
				input.className = 'correct';
				display('userlogin_help');
				close('userlogin_error');
				close('info_username');	
				bddTest('username');
			}
			else
			{
				input.className = 'incorrect';
				display('userlogin_error');
				close('userlogin_help');
			}
		break;
		case"password":
			if(/[a-zA-Z0-9]/.test(input.value)&& input.value.length >= 8 && input.value.length <= 49)
			{	
				input.className = 'correct';
				display('password_help');
				close('password_error');
				close('info_password');
			}
			else
			{
				input.className = 'incorrect';
				display('password_error');
				close('password_help');
			}
		break;
		case"password_confirm":
			if(compare('password', 'password_confirm')&& input.value != "")
			{	
				input.className = 'correct';
				display('password_confirm_help');
				close('password_confirm_error');
				close('info_password_confirm');
			}
			else
			{
				input.className = 'incorrect';
				display('password_confirm_error');
				close('password_confirm_help');
			}
		break
		case"email":
			if(/^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,6}$/.test(input.value))
			{
				input.className = 'correct';
				display('email_help');
				close('email_error');
				close('info_email');
				bddTest('email');
			}
			else
			{
				input.className = 'incorrect';
				display('email_error');
				close('email_help');
			} 
		break;
	}
}
</script>